package cn.iocoder.yudao.module.handguard.service.userbasetable8;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.handguard.controller.app.userbasetable8.vo.*;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable8.UserBaseTable8DO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.handguard.convert.userbasetable8.UserBaseTable8Convert;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable8.UserBaseTable8Mapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.handguard.enums.ErrorCodeConstants.*;

/**
 * 商业商住楼写字楼厂房一抵押 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class UserBaseTable8ServiceImpl implements UserBaseTable8Service {

    @Resource
    private UserBaseTable8Mapper userBaseTable8Mapper;

    @Override
    public Long createUserBaseTable8(UserBaseTable8CreateReqVO createReqVO) {
        // 插入
        UserBaseTable8DO userBaseTable8 = UserBaseTable8Convert.INSTANCE.convert(createReqVO);
        userBaseTable8Mapper.insert(userBaseTable8);
        // 返回
        return userBaseTable8.getId();
    }

    @Override
    public void updateUserBaseTable8(UserBaseTable8UpdateReqVO updateReqVO) {
        // 校验存在
        validateUserBaseTable8Exists(updateReqVO.getId());
        // 更新
        UserBaseTable8DO updateObj = UserBaseTable8Convert.INSTANCE.convert(updateReqVO);
        userBaseTable8Mapper.updateById(updateObj);
    }

    @Override
    public void deleteUserBaseTable8(Long id) {
        // 校验存在
        validateUserBaseTable8Exists(id);
        // 删除
        userBaseTable8Mapper.deleteById(id);
    }

    private void validateUserBaseTable8Exists(Long id) {
        if (userBaseTable8Mapper.selectById(id) == null) {
            throw exception(USER_BASE_TABLE8_NOT_EXISTS);
        }
    }

    @Override
    public UserBaseTable8DO getUserBaseTable8(Long id) {
        return userBaseTable8Mapper.selectById(id);
    }

    @Override
    public List<UserBaseTable8DO> getUserBaseTable8List(Long id) {
        LambdaQueryWrapper<UserBaseTable8DO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserBaseTable8DO::getApplicationId,id);
        return userBaseTable8Mapper.selectList(queryWrapper);
    }

    @Override
    public PageResult<UserBaseTable8DO> getUserBaseTable8Page(UserBaseTable8PageReqVO pageReqVO) {
        return userBaseTable8Mapper.selectPage(pageReqVO);
    }

    @Override
    public List<UserBaseTable8DO> getUserBaseTable8List(UserBaseTable8ExportReqVO exportReqVO) {
        return userBaseTable8Mapper.selectList(exportReqVO);
    }

}
